/*     */ package com.cr.quartz.util;
/*     */ 
/*     */ import com.cr.common.constant.ScheduleConstants;
/*     */ import com.cr.common.exception.job.TaskException;
/*     */ import com.cr.quartz.domain.SysJob;
/*     */ import org.quartz.CronScheduleBuilder;
/*     */ import org.quartz.CronTrigger;
/*     */ import org.quartz.Job;
/*     */ import org.quartz.JobBuilder;
/*     */ import org.quartz.JobDetail;
/*     */ import org.quartz.JobKey;
/*     */ import org.quartz.ScheduleBuilder;
/*     */ import org.quartz.Scheduler;
/*     */ import org.quartz.SchedulerException;
/*     */ import org.quartz.Trigger;
/*     */ import org.quartz.TriggerBuilder;
/*     */ import org.quartz.TriggerKey;
/*     */ 
/*     */ public class ScheduleUtils {
/*     */   private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) {
/*  34 */     boolean isConcurrent = "0".equals(sysJob.getConcurrent());
/*  35 */     return isConcurrent ? (Class)QuartzJobExecution.class : (Class)QuartzDisallowConcurrentExecution.class;
/*     */   }
/*     */   
/*     */   public static TriggerKey getTriggerKey(Long jobId, String jobGroup) {
/*  43 */     return TriggerKey.triggerKey("TASK_CLASS_NAME" + jobId, jobGroup);
/*     */   }
/*     */   
/*     */   public static JobKey getJobKey(Long jobId, String jobGroup) {
/*  51 */     return JobKey.jobKey("TASK_CLASS_NAME" + jobId, jobGroup);
/*     */   }
/*     */   
/*     */   public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException {
/*  59 */     Class<? extends Job> jobClass = getQuartzJobClass(job);
/*  61 */     Long jobId = job.getJobId();
/*  62 */     String jobGroup = job.getJobGroup();
/*  63 */     JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build();
/*  66 */     CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
/*  67 */     cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);
/*  71 */     CronTrigger trigger = (CronTrigger)TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)).withSchedule((ScheduleBuilder)cronScheduleBuilder).build();
/*  74 */     jobDetail.getJobDataMap().put("TASK_PROPERTIES", job);
/*  77 */     if (scheduler.checkExists(getJobKey(jobId, jobGroup)))
/*  80 */       scheduler.deleteJob(getJobKey(jobId, jobGroup)); 
/*  83 */     scheduler.scheduleJob(jobDetail, (Trigger)trigger);
/*  86 */     if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
/*  88 */       scheduler.pauseJob(getJobKey(jobId, jobGroup)); 
/*     */   }
/*     */   
/*     */   public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb) throws TaskException {
/*  98 */     switch (job.getMisfirePolicy()) {
/*     */       case "0":
/* 101 */         return cb;
/*     */       case "1":
/* 103 */         return cb.withMisfireHandlingInstructionIgnoreMisfires();
/*     */       case "2":
/* 105 */         return cb.withMisfireHandlingInstructionFireAndProceed();
/*     */       case "3":
/* 107 */         return cb.withMisfireHandlingInstructionDoNothing();
/*     */     } 
/* 109 */     throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() + "' cannot be used in cron schedule tasks", TaskException.Code.CONFIG_ERROR);
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-quartz-4.7.0.jar!\com\cr\quart\\util\ScheduleUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */